package com.wdc.list_;

import java.util.*;

public class 去重 {
    static int a = 0;
    public static void main(String[] args) {

        List<String> list = new ArrayList<>(Arrays.asList("A","B","C","A","A","B","D"));

        int s;

        if (3 > 2 - (s = a)) {
            System.out.println("jinlai"+s);
        }


        System.out.println(repeatListWay4(list));

    }


    //去重
    public static List repeatListWay(List<String> list) {
        Set<String> set = new HashSet<>(list);
        list.clear();
        System.out.println(list);
        list.addAll(set);
        return set.stream().toList();


    }

    public static List repeatListWay2(List<String> list) {

        for (int i = 0; i < list.size(); i++) {
            for (int j = i + 1; j < list.size(); j++) {
                if (list.get(i).equals(list.get(j))) {
                    list.remove(j--);
                }
            }
        }
        return list;


    }

    public static List repeatListWay3(List<String> list) {

        List ans = new ArrayList<String>();
        for (int i = 0; i < list.size(); i++) {
            if (!ans.contains(list.get(i))) {
                ans.add(list.get(i));
            }
        }

        return ans;


    }


    public static List repeatListWay4(List<String> list) {
        Set<String> set = new TreeSet<>(list);
        list.clear();
        System.out.println(list);
        list.addAll(set);
        return set.stream().toList();


    }

}
